<template>
  <el-card class="content">
    <el-form inline class="form">
      <el-form-item label="隐患排查点">
        <el-input
          placeholder="请输入查询内容"
          size="mini"
          clearable
          v-model="query.investigationPoint"
        >
        </el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" @click="getSearch"
          >查询</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      :data="preventionList"
      stripe
      size="small"
      :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }"
      class="el-table-box"
    >
      <el-table-column
        label="排查点"
        prop="investigationPoint"
        align="center"
        width="150px"
      >
      </el-table-column>
      <el-table-column
        label="排查隐患"
        prop="hiddenDanger"
        align="center"
      ></el-table-column>
      <el-table-column
        label="智能决策"
        prop="intelligentDecision"
        align="center"
      >
      </el-table-column>
      <el-table-column
        label="图片"
        prop="intelligentDecisionImage"
        align="center"
      >
        <template slot-scope="scope">
          <div @click="srcDate(scope.row)">
            <el-image
              v-if="srcLenght !== 1"
              :src="imgUrl + scope.row.intelligentDecisionImage.split(',')[0]"
              class="bigIntelligent"
              :preview-src-list="srcBigList"
            ></el-image>
            <el-image
              v-else-if="srcLenght == 1"
              :src="imgUrl + scope.row.intelligentDecisionImage"
              class="bigIntelligent"
              :preview-src-list="srcBigList"
            ></el-image>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="上报人"
        prop="reportUserName"
        align="center"
      ></el-table-column>
      <el-table-column
        label="上报时间"
        prop="createTime"
        align="center"
        width="180"
      ></el-table-column>
      <el-table-column label="处理人" align="center" prop="updateUserName">
        <template slot-scope="scope">
          <span v-if="scope.row.handleType == 0">{{
            scope.row.updateUserName
          }}</span>
          <span v-if="scope.row.handleType == 2">{{
            scope.row.updateUserName
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="处理情况" align="center" prop="status">
        <template slot-scope="scope">
          <el-button type="danger" size="small" v-if="scope.row.status == 0"
            >未处理</el-button
          >
          <el-button
            type="success"
            size="small"
            v-else-if="scope.row.status === 1"
            >已处理</el-button
          >
        </template>
      </el-table-column>
      <el-table-column label="处理图片" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.status == 0"></div>
          <div v-else-if="scope.row.status == 1">
            <div
              v-if="scope.row.handleType == 0"
              @click="handleDate(scope.row)"
            >
              <el-image
                v-if="srcLenght !== 1"
                :src="imgUrl + scope.row.handleImage.split(',')[0]"
                class="bigIntelligent"
                :preview-src-list="handelSrcBigList"
              ></el-image>
            </div>
            <div v-else-if="scope.row.handleType == 2">
              <el-image
                v-if="srcLenght == 1"
                :src="imgUrl + scope.row.turnHandleImage"
                class="bigIntelligent"
                :preview-src-list="handelSrcBigList"
              ></el-image>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="处理时间"
        prop="updateTime"
        align="center"
      ></el-table-column>
      <el-table-column label="备注" prop="handleStatus" align="left">
        <template slot-scope="scope">
          <span v-if="scope.row.handleType == 0">{{
            scope.row.handleStatus
          }}</span>
          <span v-if="scope.row.handleType == 2">{{
            scope.row.turnHandleStatus
          }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="处理方法" prop="handleStatus" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.status == 0">
            <el-button size="mini" type="text" @click="dialogVisible = true"
              >修改</el-button
            >
          </div>
          <div v-if="scope.row.status == 1"></div>
        </template>
      </el-table-column> -->
    </el-table>
    <el-row type="flex" justify="end">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.page"
        :page-sizes="[10, 15]"
        :page-size="query.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-row>
    <!-- 修改处理方法 -->
    <!-- <el-dialog title="修改处理方法" :visible.sync="dialogVisible" width="25%">
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="处理方法:">
          <el-select v-model="form.region" placeholder="请选择处理方法">
            <el-option
              v-for="item in dealTypeList"
              :key="item.id"
              :value="item.id"
              :label="item.name"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="处理备注" prop="remark">
          <el-input type="textarea" v-model="form.remark"></el-input>
        </el-form-item>
        <el-form-item style="text-align: center">
          <el-button type="primary" size="small">确定</el-button>
          <el-button size="small" @click="dialogVisible = false"
            >取消</el-button
          >
        </el-form-item>
      </el-form>
    </el-dialog> -->
  </el-card>
</template>

<script>
import { getHiddenTroubleCheck, imgUrl } from "../../api/warning";
export default {
  name: "HiddenTroubleNvestigationAndManagement",
  data() {
    return {
      tailingPondId: "",
      query: {
        page: 1,
        pagesize: 10,
        investigationPoint: "",
      },
      total: null,
      imgUrl,
      preventionList: [],
      srcLenght: null,
      // 放大图片
      srcBigList: [],
      handelSrcLenght: null,
      // 放大处理图片
      handelSrcBigList: [],
      dialogVisible: false,
      form: {
        name: "",
        region: "",
      },
      dealTypeList: [
        { id: 0, name: "恢复正常" },
        { id: 1, name: "一小时内不处理" },
        { id: 2, name: "十二小时内不处理" },
        { id: 3, name: "一天内不处理" },
        { id: 4, name: "三天内不处理" },
        { id: 5, name: "一周内不处理" },
      ],
    };
  },
  created() {
    this.tailingPondId = sessionStorage.getItem("sensorId");
    this.getPreventionListByPage();
  },
  methods: {
    async getPreventionListByPage() {
      const res = await getHiddenTroubleCheck({
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        tailingPondId: this.tailingPondId,
        investigationPoint: this.query.investigationPoint,
        unitId: sessionStorage.getItem("unitId"),
      });
      if (res.resultCode == "200") {
        this.preventionList = res.parameter.list;
        this.total = res.parameter.total;
      } else {
        this.preventionList = [];
        this.total = 0;
      }
    },
    async getSearch() {
      const res = await getHiddenTroubleCheck({
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        tailingPondId: this.tailingPondId,
        investigationPoint: this.query.investigationPoint,
        unitId: sessionStorage.getItem("unitId"),
      });
      if (res.resultCode == "200") {
        this.preventionList = res.parameter.list;
        this.total = res.parameter.total;
      } else {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.preventionList = [];
        this.total = 0;
      }
    },
    // // 监听 pagesize 改变的事件
    handleSizeChange(val) {
      this.query.pagesize = val;
      this.getPreventionListByPage();
    },
    // // 监听 页码值 改变的事件
    handleCurrentChange(val) {
      this.query.page = val;
      this.getPreventionListByPage();
    },
    srcDate(row) {
      console.log(row.intelligentDecisionImage);
      this.srcBigList = [];
      if (row.intelligentDecisionImage.indexOf(",") !== -1) {
        var ele = row.intelligentDecisionImage.split(",");
        this.srcLenght = ele.length;
        for (let i = 0; i < ele.length; i++) {
          var e = ele[i];
          this.srcBigList.push(imgUrl + e);
        }
      } else {
        this.srcBigList.push(imgUrl + row.intelligentDecisionImage);
      }
    },
    handleDate(row) {
      this.handelSrcBigList = [];
      if (row.handleType == 0) {
        if (row.handleImage.indexOf(",") !== -1) {
          var ele = row.handleImage.split(",");
          this.handelSrcLenght = ele.length;
          for (let i = 0; i < ele.length; i++) {
            var e = ele[i];
            this.handelSrcBigList.push(imgUrl + e);
          }
        } else {
          this.handelSrcBigList.push(imgUrl + row.handleImage);
        }
      } else if (row.handleType == 2) {
        if (row.turnHandleImage.indexOf(",") !== -1) {
          var ele = row.turnHandleImage.split(",");
          this.handelSrcLenght = ele.length;
          for (let i = 0; i < ele.length; i++) {
            var e = ele[i];
            this.handelSrcBigList.push(imgUrl + e);
          }
        } else {
          this.handelSrcBigList.push(imgUrl + row.turnHandleImage);
        }
      }
    },
    // //修改弹窗
    // updateInfo(row) {
    //   console.log(row);
    //   this.dialogVisible = true;
    // },
    // isEditdialogVisible() {
    //   this.$refs.form.validate((val) => {
    //     if (val) {
    //       const formData = new FormData();
    //       for (const [key, value] of Object.entries(this.form)) {
    //         formData.append(key, value);
    //       }
    //       axios({
    //         method: "post",
    //         url: "/monitorPoint/updateMonitorPoint",
    //         data: formData,
    //       }).then((res) => {
    //         console.log(res);
    //         if (res.data.resultCode == "200") {
    //           this.getPreventionListByPage();
    //           this.$message({
    //             type: "success",
    //             message: "修改成功",
    //             offset: 400,
    //             duration: 1000,
    //           });
    //           this.dialogVisible = false;
    //         } else if (res.data.resultCode == "400") {
    //           this.$message({
    //             type: "error",
    //             message: "修改失败",
    //             offset: 400,
    //             duration: 1000,
    //           });
    //         }
    //       });
    //     } else {
    //       this.$message({
    //         type: "error",
    //         message: "请完成表单",
    //         offset: 400,
    //         duration: 1000,
    //       });
    //     }
    //   });
    // },
  },
};
</script>

<style scoped>
.content {
  margin-left: 0.08rem;
  margin-right: 0.08rem;
  margin-top: 0.04rem;
  height: 89vh;
  font-size: 0.07rem;
}
.el-table {
  margin-bottom: 0.15rem;
  display: block;
  height: 67vh;
  overflow: auto;
  text-align: center;
}
.el-table::before {
  z-index: inherit;
}
.bigIntelligent {
  max-height: 0.25rem;
  max-width: 0.25rem;
  object-fit: contain;
}
.bigImg {
  max-height: 1.5rem;
  max-width: 1.5rem;
  overflow: auto;
}
.form {
  margin-left: 0.2rem;
  margin-top: 0.15rem;
}
</style>
